package com.android.huimeiqupin.view;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.huimeiqupin.R;
import com.android.huimeiqupin.activity.PayActivity;
import com.android.huimeiqupin.model.detail.MainDetail;
import com.android.huimeiqupin.model.detail.ShareDetail;
import com.android.huimeiqupin.utils.MyLog;
import com.android.huimeiqupin.utils.ObjectUtils;
import com.android.huimeiqupin.view.detail.SingleSelectCheckBoxs;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/10/17.
 */

public class CheckInchPopWindow1 implements PopupWindow.OnDismissListener, View.OnClickListener {


    private String mColorResult = null;
    private int dex;


    private TextView pop_add, pop_reduce;
    private TextView pop_num;
    private TextView pop_del;

    private PopupWindow popupWindow;
    private final int ADDORREDUCE = 1;
    private Context context;
    private ShareDetail mInfo;

    int sum = 0;
//  private SingleSelectCheckBoxs sscb_inch, sscb_color;

    private List<MainDetail.DataBean.GoodsItemBean> mSubDetailData = new ArrayList<>();
    private TextView inventory_tv;
    private TextView real_price_tv;
    private ImageView iv_adapter_grid_pic;

    private TextView ok_tv;
    private int mWhich;

    private TextView has_choose_tv;


    private String mSizeResult = null;

    private String spec;
    private ArrayList<String> mData = new ArrayList<>();
    private int sumstock;
    private String m3Result = null;
    private String m4Result = null;
    private String common_id;
    private String detailid;
    private String option;
    private int check;

    public CheckInchPopWindow1(Context context, ShareDetail info, String common_id, String detailid, int check, String option) {
        this.context = context;
        this.mInfo = info;
        this.common_id = common_id;
        this.detailid = detailid;
        this.check = check;
        this.option = option;
        View view = LayoutInflater.from(context).inflate(R.layout.popwindow_detail, null);
        showToolsView(view);
        ok_tv = (TextView) view.findViewById(R.id.ok_tv);
        pop_add = (TextView) view.findViewById(R.id.pop_add);
        pop_reduce = (TextView) view.findViewById(R.id.pop_reduce);
        pop_num = (TextView) view.findViewById(R.id.pop_num);
        pop_num.setText(1 + "");
        pop_del = (TextView) view.findViewById(R.id.pop_del);
        inventory_tv = (TextView) view.findViewById(R.id.inventory_tv);
        real_price_tv = (TextView) view.findViewById(R.id.real_price_tv);
        has_choose_tv = (TextView) view.findViewById(R.id.has_choose_tv);
        iv_adapter_grid_pic = (ImageView) view.findViewById(R.id.iv_adapter_grid_pic);
        pop_add.setOnClickListener(this);
        pop_reduce.setOnClickListener(this);
        pop_del.setOnClickListener(this);
        ok_tv.setOnClickListener(this);
        popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        popupWindow.setAnimationStyle(R.style.popWindow_anim_style);
        popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        popupWindow.setOnDismissListener(this);

        if (mInfo != null) {
            mSubDetailData = mInfo.getData().getGoods_item();

            if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                for (int i = 0; i < mSubDetailData.size(); i++) {

                    MainDetail.DataBean.GoodsItemBean s = mSubDetailData.get(i);
                    sum += Integer.parseInt(s.getStock());
                    if (check == 1) {

                        real_price_tv.setText("￥" + s.getPrice());

                    } else {
                        real_price_tv.setText("￥" + s.getTeam_price());
                    }
                    ObjectUtils.photo(context, s.getThumb(), iv_adapter_grid_pic);

                    for (int j = 0; j < lists.length; j++) {

                        if (!lists[j].contains(mSubDetailData.get(i).getSpec_array().get(j).getSpec_value()))
                        {
                            lists[j].add(mSubDetailData.get(i).getSpec_array().get(j).getSpec_value());
                        }
                    }

                }

                inventory_tv.setText("库存 " + sum);
                //添加数据
                if (lists.length == 1) {
                    m3Result = "";
                    m4Result = "";
                    mColorResult = "";
                    sscb_colors[0].setData(lists[0]);
                    if (mSubDetailData.size() == 1) {
                        mSizeResult = mSubDetailData.get(0).getSpec_array().get(0).getSpec_value();
                        //  sscb_colors[0].setOnlyOneChecked();
                        sscb_colors[select0].setOnSelectListener(new type1());
                    } else {
                        sscb_colors[select0].setOnSelectListener(new type1());
                    }
                } else if (lists.length == 2) {
                    m3Result = "";
                    m4Result = "";
                    sscb_colors[0].setData(lists[0]);
                    sscb_colors[1].setData(lists[1]);
                    if (mSubDetailData.size() == 1) {
                        mSizeResult = mSubDetailData.get(0).getSpec_array().get(0).getSpec_value();
                        mColorResult = mSubDetailData.get(0).getSpec_array().get(1).getSpec_value();
                        sscb_colors[0].setOnlyOneChecked();
                        sscb_colors[1].setOnlyOneChecked();
                    } else {
                        sscb_colors[select0].setOnSelectListener(new type1());
                        sscb_colors[select1].setOnSelectListener(new type2());
                    }
                } else if (lists.length == 3) {
                    m4Result = "";
                    sscb_colors[0].setData(lists[0]);
                    sscb_colors[1].setData(lists[1]);
                    sscb_colors[2].setData(lists[2]);
                    if (mSubDetailData.size() == 1) {
                        mSizeResult = mSubDetailData.get(0).getSpec_array().get(0).getSpec_value();
                        mColorResult = mSubDetailData.get(0).getSpec_array().get(1).getSpec_value();
                        mColorResult = mSubDetailData.get(0).getSpec_array().get(2).getSpec_value();
                        sscb_colors[0].setOnlyOneChecked();
                        sscb_colors[1].setOnlyOneChecked();
                        sscb_colors[2].setOnlyOneChecked();
                    } else {

                        sscb_colors[select0].setOnSelectListener(new type1());
                        sscb_colors[select1].setOnSelectListener(new type2());
                        sscb_colors[select2].setOnSelectListener(new type3());
                    }
                } else if (lists.length == 4) {

                    sscb_colors[0].setData(lists[0]);
                    sscb_colors[1].setData(lists[1]);
                    sscb_colors[2].setData(lists[2]);
                    sscb_colors[3].setData(lists[3]);

                    if (mSubDetailData.size() == 1) {

                        mSizeResult = mSubDetailData.get(0).getSpec_array().get(0).getSpec_value();
                        mColorResult = mSubDetailData.get(0).getSpec_array().get(1).getSpec_value();
                        mColorResult = mSubDetailData.get(0).getSpec_array().get(2).getSpec_value();
                        mColorResult = mSubDetailData.get(0).getSpec_array().get(3).getSpec_value();
                        sscb_colors[0].setOnlyOneChecked();
                        sscb_colors[1].setOnlyOneChecked();
                        sscb_colors[2].setOnlyOneChecked();
                        sscb_colors[3].setOnlyOneChecked();

                    } else {

                        sscb_colors[select0].setOnSelectListener(new type1());
                        sscb_colors[select1].setOnSelectListener(new type2());
                        sscb_colors[select2].setOnSelectListener(new type3());
                        sscb_colors[select3].setOnSelectListener(new type4());
                    }
                }

            }
        }

    }


    public void setData(int which) {

        mWhich = which;
    }

    private TextView toolsTextViews[];
    private View views[];
    private SingleSelectCheckBoxs sscb_colors[];
    private ArrayList[] lists;

    private void showToolsView(View v) {
        LinearLayout toolsLayout = (LinearLayout) v.findViewById(R.id.list_spec);
        lists = new ArrayList[mInfo.getData().getSp_arr().size()];
        for (int i = 0; i < mInfo.getData().getSp_arr().size(); i++) {

            lists[i] = new ArrayList<>();
        }
        toolsTextViews = new TextView[mInfo.getData().getSp_arr().size()];
        views = new View[mInfo.getData().getSp_arr().size()];
        sscb_colors = new SingleSelectCheckBoxs[mInfo.getData().getSp_arr().size()];

        for (int i = 0; i < mInfo.getData().getSp_arr().size(); i++) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_detail_adapter_spec_detail, null);
            view.setId(i);
            TextView textView = (TextView) view.findViewById(R.id.type);
            SingleSelectCheckBoxs sscb_color = (SingleSelectCheckBoxs) view.findViewById(R.id.sscb_color);
            textView.setText(mInfo.getData().getSp_arr().get(i).getName());
            textView.setTextSize(12);
            toolsLayout.addView(view);
            sscb_colors[i] = sscb_color;
            toolsTextViews[i] = textView;
            views[i] = view;
        }
    }


    @Override
    public void onDismiss() {

    }

    public void showAsDropDown(View parent) {
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.update();
    }

    public void dissmiss() {
        if (popupWindow != null && popupWindow.isShowing()) {
            popupWindow.dismiss();
        }
    }

    @Override
    public void onClick(View v) {

        Intent intent = new Intent(context, PayActivity.class);
        switch (v.getId()) {

            case R.id.ok_tv:
                if (mSizeResult == null || mColorResult == null || m3Result == null || m4Result == null) {
                    ObjectUtils.toast(context, "请选择完整属性");
                    return;
                }
                if (pop_num.getText().toString().trim().equals("")) {
                    pop_num.setText("1");
                }
                try {
                    int add = Integer.valueOf(pop_num.getText().toString().trim());
                    if (sumstock > 0) {
                        if (mWhich == 0) {
                            //拼团购买0   直接购买1  参团购买2
                            //普通拼团购买
                            intent.putExtra("id", detailid);
                            intent.putExtra("num", add + "");
                            intent.putExtra("spec", spec);
                            intent.putExtra("common_id", common_id);
                            intent.putExtra("option", option);
                            //类型
                            intent.putExtra("typeid",Integer.parseInt(mInfo.getData().getGoods_typeid()));
                            context.startActivity(intent);
                            dissmiss();
                        } else if (mWhich == 1) {
                            //直接购买 不需要团购id
                            intent.putExtra("id", detailid);
                            intent.putExtra("num", add + "");
                            intent.putExtra("spec", spec);
                            intent.putExtra("common_id", common_id);
                            intent.putExtra("option", option);
                            //类型
                            intent.putExtra("typeid", 0);
                            context.startActivity(intent);
                            dissmiss();
                        } else if (mWhich == 2) {

                            //参团购买  加个团购id
                            intent.putExtra("id", detailid);
                            intent.putExtra("num", add + "");
                            intent.putExtra("spec", spec);
                            intent.putExtra("common_id", common_id + "");
                            intent.putExtra("option", option);
                            intent.putExtra("typeid", Integer.parseInt(mInfo.getData().getGoods_typeid()));
                            MyLog.e("typeidpopwi",mInfo.getData().getGoods_typeid());
                            context.startActivity(intent);
                            dissmiss();
                        }
                    } else if (sumstock == 0) {
                        ObjectUtils.toast(context, "暂无库存");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


                break;
            case R.id.pop_add:
                if (mSizeResult == null || mColorResult == null || m3Result == null || m4Result == null) {
                    ObjectUtils.toast(context, "请选择完整属性");
                    return;
                }
                if (pop_num.getText().toString().equals("")) {

                    pop_num.setText("1");

                }
                try {

                    int add = Integer.valueOf(pop_num.getText().toString().trim());

                    if (sumstock == 0) {

                        ObjectUtils.toast(context, "暂无库存");
                        return;

                    }
                    if (add < sumstock && sumstock != 0) {

                        add++;
                        pop_num.setText(add + "");

                    } else {

                        pop_num.setText(sumstock + "");
                        ObjectUtils.toast(context, "您最多只能购买这么多了");

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


                break;
            case R.id.pop_reduce:

                if (mSizeResult == null || mColorResult == null || m3Result == null || m4Result == null) {


                    ObjectUtils.toast(context, "请选择完整属性");

                    return;

                }
                if (pop_num.getText().toString().equals("")) {

                    pop_num.setText("1");

                }
                try {

                    int add = Integer.valueOf(pop_num.getText().toString().trim());

                    if (sumstock == 0) {

                        ObjectUtils.toast(context, "暂无库存");
                        return;

                    }
                    if (add > 1 && sumstock != 0) {

                        add--;
                        pop_num.setText(add + "");

                    } else {
                        ObjectUtils.toast(context, "购买数量必须为正数");
                        pop_num.setText("1");

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }


                break;
            // 关闭popwindow
            case R.id.pop_del:

                dissmiss();

                break;

            default:
                break;
        }

    }


    private void getResult2Show(MainDetail.DataBean.GoodsItemBean result) {


        if (mSizeResult == null || mColorResult == null || m3Result == null) {
            ObjectUtils.toast(context, "请选择完整属性");

        } else {
            sumstock = Integer.parseInt(result.getStock());
            inventory_tv.setText("库存" + sumstock);
            spec = result.getSpec();
            if (lists.length == 1) {

                has_choose_tv.setText(result.getSpec_array().get(0).getSpec_value());

            } else if (lists.length == 2) {

                has_choose_tv.setText(result.getSpec_array().get(0).getSpec_value() + "/" + result.getSpec_array().get(1).getSpec_value());
            } else {

                has_choose_tv.setText(result.getSpec_array().get(0).getSpec_value() + "/" + result.getSpec_array().get(1).getSpec_value()
                        + "/" + result.getSpec_array().get(2).getSpec_value());

            }

            if (check == 1) {
                real_price_tv.setText((mInfo.getData().getGoods_item().size() > 0) ? "¥" + result.getPrice() : "¥");

            } else {
                real_price_tv.setText((mInfo.getData().getGoods_item().size() > 0) ? "¥" + result.getTeam_price() : "¥");


            }
            ObjectUtils.photo(context, result.getThumb(), iv_adapter_grid_pic);

        }

    }

    int select0 = 0;
    int select1 = 1;
    int select2 = 2;
    int select3 = 3;

    private class type1 implements SingleSelectCheckBoxs.OnSelectListener {
        @Override
        public void onSelect(int position) {

            if (position != -1) {
                MyLog.e("doinfsd2","dfsdfsdfs");
                if (lists.length == 1) {
                    mSizeResult = (String) lists[select0].get(position);
                    sscb_colors[select0].setData(mSizeResult, true);
                    if (!TextUtils.isEmpty(mSizeResult)) {
                        MainDetail.DataBean.GoodsItemBean result = null;
                        if (mSubDetailData != null && !mSubDetailData.isEmpty()) {
                            for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {
                                if (p.getSpec_array().get(select0).getSpec_value().equals(mSizeResult)) {
                                    result = p;
                                }
                            }
                        }
                        getResult2Show(result);
                    }
                } else {
                    //list1
                    mSizeResult = (String) lists[select0].get(position);
                    ArrayList<String> temp_size = new ArrayList<>();
                    if (mSubDetailData != null && !mSubDetailData.isEmpty()) {
                        for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {
                            if (p.getSpec_array().get(select0).getSpec_value().equals(mSizeResult)) {
                                temp_size.add(p.getSpec_array().get(select1).getSpec_value());
                            }
                        }
                    }
                    if (lists[select1] != null && !lists[select1].isEmpty()) {

                        ArrayList<String> list2 = lists[select1];
                        for (String str : list2) {

                            sscb_colors[select1].setData(str, false);

                            if (temp_size != null && !temp_size.isEmpty()) {

                                for (String canEnable : temp_size) {

                                    if (canEnable.equals(str)) {

                                        sscb_colors[select1].setData(str, true);

                                    }


                                }


                            }

                        }

                    }


                    if (!TextUtils.isEmpty(mColorResult) && m3Result != null) {

                        MainDetail.DataBean.GoodsItemBean result = null;

                        if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                            for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                                if (p.getSpec_array().get(select0).getSpec_value().equals(mSizeResult) && p.getSpec_array().get(select1).getSpec_value().equals(mColorResult)) {

                                    result = p;

                                }

                            }

                        }

                        getResult2Show(result);

                    }


                }
            } else {
                MyLog.e("doinfsd1","dfsdfsdfs");
//                mSizeResult = null;
//                if (lists.length > 1) {
//
//                    if (lists[select1] != null && !lists[select1].isEmpty()) {
//                        ArrayList<String> list2 = lists[select1];
//                        for (String str : list2) {
//                            sscb_colors[select1].setData(str, true);
//                        }
//
//                    }
//                }
//                inventory_tv.setText("库存" + sum);
//                has_choose_tv.setText("请选择完整");


            }

        }
    }

    private class type2 implements SingleSelectCheckBoxs.OnSelectListener {


        @Override
        public void onSelect(int position) {

            if (position != -1) {
                //list1
                mColorResult = (String) lists[select1].get(position);

                ArrayList<String> temp_size = new ArrayList<>();

                if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                    for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                        if (p.getSpec_array().get(select1).getSpec_value().equals(mColorResult)) {

                            temp_size.add(p.getSpec_array().get(select0).getSpec_value());

                        }

                    }


                }

                if (lists[select0] != null && !lists[select0].isEmpty()) {

                    ArrayList<String> list2 = lists[select0];
                    for (String str : list2) {

                        sscb_colors[select0].setData(str, false);

                        if (temp_size != null && !temp_size.isEmpty()) {

                            for (String canEnable : temp_size) {

                                if (canEnable.equals(str)) {

                                    sscb_colors[select0].setData(str, true);

                                }


                            }


                        }

                    }

                }

                if (lists.length == 2) {


                } else if (lists.length == 3) {


                }
                if (!TextUtils.isEmpty(mSizeResult) && m3Result != null) {
                    MainDetail.DataBean.GoodsItemBean result = null;

                    if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                        for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                            if (p.getSpec_array().get(select1).getSpec_value().equals(mColorResult) && p.getSpec_array().get(select0).getSpec_value().equals(mSizeResult)) {

                                result = p;

                            }

                        }

                    }

                    getResult2Show(result);

                }

            } else {

                mColorResult = null;


                if (lists[select0] != null && !lists[select0].isEmpty()) {
                    ArrayList<String> list2 = lists[select0];
                    for (String str : list2) {

                        sscb_colors[select0].setData(str, true);

                    }

                }
                inventory_tv.setText("库存" + sum);
                has_choose_tv.setText("请选择完整");

            }

        }
    }


    private class type3 implements SingleSelectCheckBoxs.OnSelectListener {


        @Override
        public void onSelect(int position) {

            if (position != -1) {
                //list1
                m3Result = (String) lists[select2].get(position);

                ArrayList<String> temp_size1 = new ArrayList<>();
                ArrayList<String> temp_size2 = new ArrayList<>();

                if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                    for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                        if (p.getSpec_array().get(select2).getSpec_value().equals(m3Result)) {

                            temp_size1.add(p.getSpec_array().get(select0).getSpec_value());
                            temp_size2.add(p.getSpec_array().get(select1).getSpec_value());

                        }

                    }


                }

                if (lists[select0] != null && !lists[select0].isEmpty() && lists[select1] != null && !lists[select1].isEmpty()) {

                    ArrayList<String> list2 = lists[select0];
                    for (String str : list2) {

                        sscb_colors[select0].setData(str, false);

                        if (temp_size1 != null && !temp_size1.isEmpty()) {

                            for (String canEnable : temp_size1) {

                                if (canEnable.equals(str)) {

                                    sscb_colors[select0].setData(str, true);

                                }


                            }


                        }

                    }
                    ArrayList<String> list = lists[select1];
                    for (String str : list) {

                        sscb_colors[select1].setData(str, false);

                        if (temp_size2 != null && !temp_size2.isEmpty()) {

                            for (String canEnable : temp_size2) {

                                if (canEnable.equals(str)) {

                                    sscb_colors[select1].setData(str, true);

                                }


                            }


                        }

                    }


                }


                if (!TextUtils.isEmpty(mSizeResult) && !TextUtils.isEmpty(mColorResult)) {


                    MainDetail.DataBean.GoodsItemBean result = null;

                    if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                        for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                            if (p.getSpec_array().get(select1).getSpec_value().equals(mColorResult) && p.getSpec_array().get(select0).getSpec_value().equals(mSizeResult)
                                    && p.getSpec_array().get(select2).getSpec_value().equals(m3Result)) {

                                result = p;

                            }

                        }

                    }

                    getResult2Show(result);

                }

            } else {

                m3Result = null;


                if (lists[select0] != null && !lists[select0].isEmpty()) {
                    ArrayList<String> list2 = lists[select0];
                    for (String str : list2) {

                        sscb_colors[select0].setData(str, true);

                    }


                }


                if (lists[select1] != null && !lists[select1].isEmpty()) {
                    ArrayList<String> list = lists[select1];
                    for (String str : list) {

                        sscb_colors[select1].setData(str, true);

                    }

                }

                inventory_tv.setText("库存" + sum);
                has_choose_tv.setText("请选择完整");

            }

        }
    }

    private class type4 implements SingleSelectCheckBoxs.OnSelectListener {


        @Override
        public void onSelect(int position) {

            if (position != -1) {
                //list1
                m4Result = (String) lists[select3].get(position);

                ArrayList<String> temp_size1 = new ArrayList<>();
                ArrayList<String> temp_size2 = new ArrayList<>();
                ArrayList<String> temp_size3 = new ArrayList<>();

                if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                    for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                        if (p.getSpec_array().get(select3).getSpec_value().equals(m4Result)) {

                            temp_size1.add(p.getSpec_array().get(select0).getSpec_value());
                            temp_size2.add(p.getSpec_array().get(select1).getSpec_value());
                            temp_size3.add(p.getSpec_array().get(select2).getSpec_value());

                        }

                    }


                }

                if (lists[select0] != null && !lists[select0].isEmpty() && lists[select1] != null && !lists[select1].isEmpty() && lists[select2] != null && !lists[select2].isEmpty()) {

                    ArrayList<String> list2 = lists[select0];
                    for (String str : list2) {

                        sscb_colors[select0].setData(str, false);

                        if (temp_size1 != null && !temp_size1.isEmpty()) {

                            for (String canEnable : temp_size1) {

                                if (canEnable.equals(str)) {

                                    sscb_colors[select0].setData(str, true);

                                }


                            }


                        }

                    }
                    ArrayList<String> list = lists[select1];
                    for (String str : list) {

                        sscb_colors[select1].setData(str, false);

                        if (temp_size2 != null && !temp_size2.isEmpty()) {

                            for (String canEnable : temp_size2) {

                                if (canEnable.equals(str)) {

                                    sscb_colors[select1].setData(str, true);

                                }


                            }


                        }

                    }
                    ArrayList<String> list3 = lists[select2];
                    for (String str : list3) {

                        sscb_colors[select2].setData(str, false);

                        if (temp_size3 != null && !temp_size3.isEmpty()) {

                            for (String canEnable : temp_size3) {

                                if (canEnable.equals(str)) {

                                    sscb_colors[select2].setData(str, true);

                                }


                            }


                        }

                    }

                }


                if (!TextUtils.isEmpty(mSizeResult) && !TextUtils.isEmpty(mColorResult) && !TextUtils.isEmpty(m3Result)) {


                    MainDetail.DataBean.GoodsItemBean result = null;

                    if (mSubDetailData != null && !mSubDetailData.isEmpty()) {

                        for (MainDetail.DataBean.GoodsItemBean p : mSubDetailData) {

                            if (p.getSpec_array().get(select1).getSpec_value().equals(mColorResult) && p.getSpec_array().get(select0).getSpec_value().equals(mSizeResult)
                                    && p.getSpec_array().get(select2).getSpec_value().equals(m3Result) && p.getSpec_array().get(select3).getSpec_value().equals(m4Result)) {

                                result = p;

                            }

                        }

                    }

                    getResult2Show(result);

                }

            } else {

                m4Result = null;


                if (lists[select0] != null && !lists[select0].isEmpty()) {
                    ArrayList<String> list2 = lists[select0];
                    for (String str : list2) {

                        sscb_colors[select0].setData(str, true);

                    }


                }


                if (lists[select1] != null && !lists[select1].isEmpty()) {
                    ArrayList<String> list = lists[select1];
                    for (String str : list) {

                        sscb_colors[select1].setData(str, true);

                    }

                }
                if (lists[select2] != null && !lists[select2].isEmpty()) {
                    ArrayList<String> list = lists[select2];
                    for (String str : list) {

                        sscb_colors[select2].setData(str, true);

                    }

                }

                inventory_tv.setText("库存" + sum);
                has_choose_tv.setText("请选择完整");

            }

        }
    }

}
